

package jetbrains.buildServer.server.rest.model;

import jetbrains.buildServer.server.rest.data.finder.BaseFinderTest;
import jetbrains.buildServer.server.rest.model.project.Project;
import jetbrains.buildServer.serverSide.SProject;
import jetbrains.buildServer.serverSide.SimpleParameter;
import jetbrains.buildServer.serverSide.impl.ProjectEx;
import jetbrains.buildServer.serverSide.impl.projects.ProjectImpl;
import org.testng.annotations.Test;

public class ProjectTest extends BaseFinderTest<SProject> {

  @Test
  public void testVirtualProject() {
    ProjectEx project = createProject("virtualProject");
    project.addParameter(new SimpleParameter(ProjectImpl.TEAMCITY_VIRTUAL_PROJECT_PARAM, "true"));

    Project projectModel;

    projectModel = new Project(project, new Fields("virtual"), getBeanContext(myFixture));
    assertTrue("Must return Project.virtual=true if requested ny name", projectModel.isVirtual());

    projectModel = new Project(project, Fields.LONG, getBeanContext(myFixture));
    assertTrue("Must return Project.virtual=true if $long", projectModel.isVirtual());

    projectModel = new Project(project, Fields.SHORT, getBeanContext(myFixture));
    assertNull(projectModel.isVirtual());
  }

  @Test
  public void testNonVirtualProject() {
    ProjectEx project = createProject("nonVirtualProject");
    project.addParameter(new SimpleParameter(ProjectImpl.TEAMCITY_VIRTUAL_PROJECT_PARAM, "false"));

    Project projectModel;

    projectModel = new Project(project, new Fields("virtual"), getBeanContext(myFixture));
    assertFalse("Must return Project.virtual=false if requested ny name", projectModel.isVirtual());

    projectModel = new Project(project, Fields.LONG, getBeanContext(myFixture));
    assertFalse("Must return Project.virtual=false if $long", projectModel.isVirtual());

    projectModel = new Project(project, Fields.SHORT, getBeanContext(myFixture));
    assertNull(projectModel.isVirtual());
  }
}